﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>工序不合格原因数据查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'工序不合格原因报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :rules="rules" style="margin: 10px"
        :label-position="'left'">

        <el-form-item label="主制分厂:" prop="factoryid">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择主制分厂" clearable filterable @change="bindControl">
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="检验时间:">
          <el-date-picker v-model="queryInfo.checkDate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="操作者:">
          <el-input v-model.trim="queryInfo.operator" placeholder="请输入操作者" clearable style="width:150px;"></el-input>
        </el-form-item>

        <el-form-item label="检验员:">
          <el-select v-model="queryInfo.jianyanyuan" placeholder="请选择检验员" clearable filterable style="width:150px;">
            <el-option v-for="p in jianyanyuanList" :key="p.employeeid" :label="p.fullname" :value="p.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="工艺员:">
          <el-select v-model="queryInfo.gongyiyuan" placeholder="请选择工艺员" clearable filterable style="width:150px;">
            <el-option v-for="p in gongyiyuanList" :key="p.employeeid" :label="p.fullname" :value="p.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="机型:">
          <el-select v-model="queryInfo.productfamilyname" placeholder="请选择机型" clearable filterable>
            <el-option v-for="i in productFamilyList" :key="i.productfamilyname" :label="i.productfamilyname"
              :value="i.productfamilyname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='containername' label="批次号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入批次号" :trigger-on-focus="false"
            clearable style="width:240px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'"
            :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="工序号:">
          <el-input v-model.trim="queryInfo.specno" placeholder="请输入工序号" clearable style="width:130px;"></el-input>
        </el-form-item>

        <el-form-item prop='unqualifiedfeature' label="不合格特征:">
          <el-input v-model="queryInfo.unqualifiedfeature" placeholder="请输入不合格特征" clearable></el-input>
        </el-form-item>

        <el-form-item prop='unqualifiedreasoncode' label="不合格原因代码:">
          <el-input v-model.trim="queryInfo.unqualifiedreasoncode" placeholder="请输入不合格原因代码" clearable></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" element-loading-text="数据加载中"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border show-overflow-tooltip>
        <el-table-column type="index" width="50px" label="序号"></el-table-column>
        <el-table-column prop="mfgordername" label="生产订单" width="140px"></el-table-column>
        <el-table-column prop="containername" label="件号/批次号" width="140px"></el-table-column>
        <el-table-column prop="productname" label="件号名称" width="120px" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productrevision" label="件号版本" show-overflow-tooltip></el-table-column>
        <el-table-column prop="workflowinfo" label="工艺版次" width="140px" show-overflow-tooltip></el-table-column>
        <el-table-column prop="specno" label="工序号"></el-table-column>
        <el-table-column prop="workflowstepname" label="工序名称" width="150px" show-overflow-tooltip></el-table-column>
        <el-table-column prop="operator" label="操作者" width="160" show-overflow-tooltip></el-table-column>
        <el-table-column prop="reportdate" label="报工时间" width="150" :formatter="replaceDate"></el-table-column>
        <el-table-column prop="checkername" label="检验员" width="120px"></el-table-column>
        <el-table-column prop="checkdate" label="检验时间" width="150px" :formatter="replaceDate"></el-table-column>
        <el-table-column prop="reworkqty" label="返修数" width="100px"></el-table-column>
        <el-table-column prop="unqualifiedfeature" label="不合格特征" width="150px" show-overflow-tooltip></el-table-column>
        <el-table-column prop="unqualifiedreasoncode" label="不合格原因代码" width="130px" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="gongyiyuan" label="工艺员" width="100px"></el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[15,20,50]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { getParams, fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getProductFamily, getFactory, getFactoryUsersByRoleName, getWorkcenterList, getUserInfo } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { replaceDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        replaceDate,
        loading: false,
        total: 0,
        queryInfo: {
          factoryid: '',//主制分厂
          checkDate: '',// 检验时间
          operator: '',//操作者
          jianyanyuan: '',//检验员
          gongyiyuan: '',// 工艺员
          productfamilyname: '',// 机型
          containername: '',// 批次号
          specno: '',//工序号
          unqualifiedfeature: '',//不合格特征
          unqualifiedreasoncode: '',//不合格原因代码
          currentPage: 1,//当前页
          pageSize: 15//每页显示条数
        },
        dataList: [],
        factoryList: [],
        productFamilyList: [],
        factoryDiaoDuYuanList: [],
        jianyanyuanList: [],//检验员
        gongyiyuanList: [],// 工艺员
        // 表单验证
        rules: { factoryid: [{ required: true, message: '主制分厂不能为空', trigger: 'change' }] },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback });
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback });
        },
        async bindControl(factoryid) {
          this.queryInfo.workcenterid = null;
          this.queryInfo.workerid = null;
          if (factoryid) {
            this.jianyanyuanList = await getFactoryUsersByRoleName({ factoryid, rolename: '检验员' });
            this.gongyiyuanList = await getFactoryUsersByRoleName({ factoryid, rolename: '工艺员' });
          }
        },
        // 查询数据
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.loading = true;
              this.loadingText = '数据加载中...';
              const { data: { data, meta, total } } = await axios.post('../handler/report/UnqualifiedReasonSpec.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              this.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.dataList = data;
              this.total = total;
            }
          })
        },
        //导出excel
        async getExportExcel() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              const config = {
                url: '../handler/report/UnqualifiedReasonSpec.ashx?action=exportExcel',
                data: { type: 'exportExcel', ...this.queryInfo }
              }
              exportExcelData(config, this);
            }
          })
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      async mounted() {
        this.productFamilyList = await getProductFamily();
        this.factoryList = await getFactory();
        const userInfo = await getUserInfo({ employeeid: getParams("uid") });
        const { factoryid } = this.factoryList.some(i => i.factoryid === userInfo.factoryid) ? userInfo : this.factoryList[0];
        this.queryInfo.factoryid = factoryid;
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>